var city="沧州";
function loadXMLDoc()
{
    var xmlhttp;
    if (window.XMLHttpRequest)
    {
        //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        // IE6, IE5 浏览器执行代码
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            var json=JSON.parse(xmlhttp.responseText);
            console.log(json);
            document.querySelector("#city").innerHTML=json.basic.city;
            document.querySelector("#cond").innerHTML=json.now.cond.txt;
            document.querySelector("#tmp").innerHTML=json.now.tmp;
            document.querySelector("#wind").innerHTML=json.now.wind.dir;
            document.querySelector("#sc").innerHTML=json.now.wind.sc;
            document.querySelector("#hum").innerHTML=json.now.hum;
            document.querySelector("#trav").innerHTML=json.suggestion.trav.txt;
            document.querySelector("#drsg_brf").innerHTML=json.suggestion.drsg.brf;
            document.querySelector("#drsg_txt").innerHTML=json.suggestion.drsg.txt;
            document.querySelector("#uv_brf").innerHTML=json.suggestion.uv.brf;
            document.querySelector("#uv_txt").innerHTML=json.suggestion.uv.txt;
            document.querySelector("#sport_brf").innerHTML=json.suggestion.sport.brf;
            document.querySelector("#sport_txt").innerHTML=json.suggestion.sport.txt;
            document.querySelector("#cw_brf").innerHTML=json.suggestion.cw.brf;
            document.querySelector("#cw_txt").innerHTML=json.suggestion.cw.txt;
            document.querySelector("#trav_brf").innerHTML=json.suggestion.trav.brf;
            document.querySelector("#trav_txt").innerHTML=json.suggestion.trav.txt;
            document.querySelector("#comf_brf").innerHTML=json.suggestion.comf.brf;
            document.querySelector("#comf_txt").innerHTML=json.suggestion.comf.txt;

            var l=json.hourly_forecast;
            console.log(l);
            for(let i=0;i<l.length;i++){
                console.log(i);
                document.querySelectorAll(".date")[i].innerHTML=json.hourly_forecast[i].date.slice(10,16);
                document.querySelectorAll(".now")[i].innerHTML=json.hourly_forecast[i].cond.txt;
                document.querySelectorAll(".tmp_1")[i].innerHTML=json.hourly_forecast[i].tmp;

            }
            var a=json.daily_forecast;
            for (let j=0;j<a.length;j++){
                document.querySelectorAll(".date_1")[j].innerHTML=json.daily_forecast[j].date;
                document.querySelectorAll(".now_1")[j].innerHTML=json.daily_forecast[j].cond.txt_d;
                document.querySelectorAll(".tmp_max")[j].innerHTML=json.daily_forecast[j].tmp.max+"°";
                document.querySelectorAll(".tmp_min")[j].innerHTML=json.daily_forecast[j].tmp.min+"°";
                document.querySelectorAll(".dir")[j].innerHTML=json.daily_forecast[j].wind.dir;
                document.querySelectorAll(".sc")[j].innerHTML=json.daily_forecast[j].wind.sc;
            }
            //document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
        }
    };
    xmlhttp.open("GET","https://bird.ioliu.cn/weather?city="+city,true);
    xmlhttp.send();
}

loadXMLDoc();

document.querySelector("#ipt").addEventListener('change',function(){
    city=this.value;
    loadXMLDoc();
});